package Exception;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author: Miyako
 * @Date: 2024-07-18-10:42
 * @Description: 使用 throws关键字抛出异常
 *
 */
public class ThrowsExceptionDemo01 {
    public static void main(String[] args) throws IOException {
        try{
            doWrite(6);//这里接收到异常，然后抛出异常
        }catch (IOException e){
            System.out.println("记录日志");
            throw new RuntimeException("运行异常");
        }

    }
    static void  doWrite(int i) throws IOException {
        try (FileOutputStream fileOutputStream = new FileOutputStream("6/test.txt")){
            fileOutputStream.write(i);
        } catch (IOException e) {
            System.out.println("读写文件失败");
            throw e;//这里将e抛出，传给main函数然后记录日志然后抛出运行时异常
        }
    }
}
